home *** CD-ROM | disk | FTP | other *** search
/ Software USA 4 #11 / Software USA Volume 4.11.iso / mac / Educational / mac06 / include / ucode.h < prev   
Encoding:
C/C++ Source or Header  |  1998-07-25  |  2.8 KB  |  116 lines  |  [TEXT/KAHL]

  1. /*
  2. ** universal code (ucode)
  3. */
  4.  
  5. #pragma once
  6.  
  7. struct ucode
  8.     {
  9.     unsigned char *text, *data, *bss, *stack, *exstack;            /* code segments */
  10.     unsigned char *textend, *dataend, *bssend, *stackend, *exend;    /* end of segments */
  11.     unsigned long *pc;            /* program pointer */
  12.     unsigned long *sp;            /* call, args, auto stack pointer */
  13.     unsigned long *tos;            /* expression stack */
  14.     };
  15.  
  16. enum { /* opcodes in upper 8 bits of command */
  17.     /* constants */
  18.     OPC_CONST=0,        /* 24 bit positive constant */
  19.     OPC_NCONST,            /* 24 bit negative constant */
  20.     OPC_HCONST,            /* 24 bit high part of constant added to tos */
  21.     OPC_TEXT=8,            /* 24 bit offset into text segment */
  22.     OPC_DATA,            /* 24 bit offset into data segment */
  23.     OPC_BSS,            /* 24 bit offset into bss segment */
  24.     /* program flow */
  25.     OPC_CALL=0x10,        /* call tos */
  26.     OPC_JMP,            /* jmp to tos */
  27.     OPC_JTRUE,            /* jump to tos if nos true */
  28.     OPC_JFALSE,            /* jump to tos if nos false */
  29.     OPC_RET,            /* return */
  30.     OPC_SETJMP,            /* set jump (tos=addr of jmpbuf) */
  31.     OPC_LONGJMP,        /* long jump (tos=addr of jmpbuf) */
  32.     /* switch/case program flow */
  33.     OPC_SWITCHSRCH,        /* search table for switch */
  34.     OPC_SWITCHJMP,        /* jmp table for switch */
  35.     /* stack manipulation */
  36.     OPC_PUSH=0x20,        /* push tos on stack */
  37.     OPC_POP,            /* pop from stack */
  38.     OPC_ALLOC,            /* allocate/deallocate space stack */
  39.     OPC_AUTO,            /* make stack offset */
  40.     /* binary arithmetic and logical operations */
  41.     OPC_ADD=0x30,
  42.     OPC_SUB,
  43.     OPC_MUL,
  44.     OPC_UMUL,
  45.     OPC_DIV,
  46.     OPC_UDIV,
  47.     OPC_MOD,
  48.     OPC_UMOD,
  49.     OPC_AND,
  50.     OPC_OR,
  51.     OPC_XOR,
  52.     /* binary shift operations */
  53.     OPC_SHL=0x40,
  54.     OPC_USHL,
  55.     OPC_SHR,
  56.     OPC_USHR,
  57.     /* binary compare operations */
  58.     OPC_LT=0x50,
  59.     OPC_ULT,
  60.     OPC_GT,
  61.     OPC_UGT,
  62.     OPC_LE,
  63.     OPC_ULE,
  64.     OPC_GE,
  65.     OPC_UGE,
  66.     OPC_EQ,
  67.     OPC_NEQ,
  68.     /* unary operations */
  69.     OPC_EQZ=0x60,
  70.     OPC_NZ,
  71.     OPC_NEG,
  72.     OPC_NOT,
  73.     OPC_CHS,
  74.     OPC_SHIFT,            /* multiply by 2 - for fast index calculations */
  75.     OPC_SEXTB,            /* sign extend byte -> long */
  76.     OPC_SEXTW,            /* sign extend word -> long */
  77.     /* working stack manipulation */
  78.     OPC_DUP=0x70,        /* duplicate value */
  79.     OPC_SWAP,            /* swap tos and nos */
  80.     OPC_DROP,            /* throw away value */
  81.     OPC_NDUP,            /* duplicate n-th value */
  82.     /* store to memory */
  83.     OPC_STOREB=0x80,
  84.     OPC_STOREW,
  85.     OPC_STOREL,
  86.     OPC_STOREF,
  87.     OPC_STORED,
  88.     /* fetch from memory */
  89.     OPC_FETCHB=0x90,
  90.     OPC_FETCHW,
  91.     OPC_FETCHL,
  92.     OPC_FETCHF,
  93.     OPC_FETCHD,
  94.     OPC_UFETCHB,
  95.     OPC_UFETCHW,
  96.     OPC_UFETCHL,
  97.     /* floating point operations */
  98.     OPC_FADD=0xa0,        /* dyadic */
  99.     OPC_FSUB,
  100.     OPC_FMUL,
  101.     OPC_FDIV,
  102.     OPC_FNEG=0xb0,        /* monadic */
  103.     OPC_ITOF,            /* integer to double */
  104.     OPC_FTOI,            /* double to integer */
  105.     /* system call */
  106.     OPC_SVC=0xc0,        /* supervisor call */
  107.     /* builtin functions */
  108.     OPC_CPYINC,            /* block copy with inc mode */
  109.     OPC_CPYDEC,            /* block copy with dec mode */
  110.     OPC_SET,            /* set block */
  111.     OPC_SRCH            /* search in block */
  112.     };
  113.  
  114. void run(struct ucode *c, register long n);
  115.  
  116. /* EOF */